From 1fe60e14e4687cf076d34c2577a9c84b3b9ba460 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20H=C3=A4rdeman?= Date: Mon, 24 Nov 2025 00:19:15 +0100 Subject: [PATCH] odhcpd: remove OAF_STATIC MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This flag does nothing more than document if lease_cfg is set in the respective dhcpv[46]_lease structs. Signed-off-by: David Härdeman Link: https://github.com/openwrt/odhcpd/pull/331 Signed-off-by: Álvaro Fernández Rojas --- src/dhcpv4.c | 12 +++++------- src/dhcpv6-ia.c | 6 ++---- src/odhcpd.h | 5 ++--- src/ubus.c | 4 ++-- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/dhcpv4.c b/src/dhcpv4.c index c41c13d..ab1a762 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -589,7 +589,7 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re lease->flags &= ~OAF_BOUND; - if (!(lease->flags & OAF_STATIC) || lease->lease_cfg->ipv4.s_addr != lease->ipv4.s_addr) { + if (!lease->lease_cfg || lease->lease_cfg->ipv4.s_addr != lease->ipv4.s_addr) { memset(lease->hwaddr, 0, sizeof(lease->hwaddr)); lease->valid_until = now + 3600; /* Block address for 1h */ } else { @@ -603,9 +603,9 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re return NULL; /* Old lease, but with an address that is out-of-scope? */ - if (lease && ((lease->ipv4.s_addr & iface->dhcpv4_own_ip.netmask) != - (iface->dhcpv4_start_ip.s_addr & iface->dhcpv4_own_ip.netmask)) && - !(lease->flags & OAF_STATIC)) { + if (lease && !lease->lease_cfg && + ((lease->ipv4.s_addr & iface->dhcpv4_own_ip.netmask) != + (iface->dhcpv4_start_ip.s_addr & iface->dhcpv4_own_ip.netmask))) { /* Try to reassign to an address that is in-scope */ avl_delete(&iface->dhcpv4_leases, &lease->iface_avl); lease->ipv4.s_addr = INADDR_ANY; @@ -634,8 +634,6 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re } if (lease_cfg) { - lease->flags |= OAF_STATIC; - if (lease_cfg->hostname) { lease->hostname = strdup(lease_cfg->hostname); lease->hostname_valid = true; @@ -663,7 +661,7 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re break; } - if ((!(lease->flags & OAF_STATIC) || !lease->hostname) && req_hostname_len > 0) { + if (req_hostname_len > 0 && (!lease->lease_cfg || !lease->lease_cfg->hostname)) { char *new_name = realloc(lease->hostname, req_hostname_len + 1); if (new_name) { lease->hostname = new_name; diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c index cc27e5b..1b17cf7 100644 --- a/src/dhcpv6-ia.c +++ b/src/dhcpv6-ia.c @@ -1171,8 +1171,6 @@ proceed: assigned = assign_na(iface, a); if (lease_cfg && assigned) { - a->flags |= OAF_STATIC; - if (lease_cfg->hostname) { a->hostname = strdup(lease_cfg->hostname); a->hostname_valid = true; @@ -1240,7 +1238,7 @@ proceed: ((hdr->msg_type == DHCPV6_MSG_SOLICIT && rapid_commit) || hdr->msg_type == DHCPV6_MSG_REQUEST || hdr->msg_type == DHCPV6_MSG_REBIND)) { - if ((!(a->flags & OAF_STATIC) || !a->hostname) && hostname_len > 0) { + if (hostname_len > 0 && (!a->lease_cfg || !a->lease_cfg->hostname)) { char *tmp = realloc(a->hostname, hostname_len + 1); if (tmp) { a->hostname = tmp; @@ -1277,7 +1275,7 @@ proceed: } else if ((a->flags & OAF_DHCPV6_NA) && hdr->msg_type == DHCPV6_MSG_DECLINE) { a->flags &= ~OAF_BOUND; - if (!(a->flags & OAF_STATIC) || a->lease_cfg->hostid != a->assigned_host_id) { + if (!a->lease_cfg || a->lease_cfg->hostid != a->assigned_host_id) { memset(a->duid, 0, a->duid_len); a->valid_until = now + 3600; /* Block address for 1h */ } else diff --git a/src/odhcpd.h b/src/odhcpd.h index d4b87cf..d7a32bb 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -192,9 +192,8 @@ enum odhcpd_mode { enum odhcpd_assignment_flags { OAF_TENTATIVE = (1 << 0), OAF_BOUND = (1 << 1), - OAF_STATIC = (1 << 2), - OAF_DHCPV6_NA = (1 << 3), - OAF_DHCPV6_PD = (1 << 4), + OAF_DHCPV6_NA = (1 << 2), + OAF_DHCPV6_PD = (1 << 3), }; /* 2-byte type + 128-byte DUID, RFC8415, §11.1 */ diff --git a/src/ubus.c b/src/ubus.c index eebedf0..5cbd09d 100644 --- a/src/ubus.c +++ b/src/ubus.c @@ -62,7 +62,7 @@ static int handle_dhcpv4_leases(struct ubus_context *ctx, _o_unused struct ubus_ if (c->flags & OAF_BOUND) blobmsg_add_string(&b, NULL, "bound"); - if (c->flags & OAF_STATIC) + if (c->lease_cfg) blobmsg_add_string(&b, NULL, "static"); if (!c->hostname_valid) @@ -154,7 +154,7 @@ static int handle_dhcpv6_leases(_o_unused struct ubus_context *ctx, _o_unused st if (a->flags & OAF_BOUND) blobmsg_add_string(&b, NULL, "bound"); - if (a->flags & OAF_STATIC) + if (a->lease_cfg) blobmsg_add_string(&b, NULL, "static"); blobmsg_close_array(&b, m); -- 2.30.2